package com.chezhujie.www.service;

import java.util.List;
import java.util.Map;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.chezhujie.www.domain.Tclause;
import com.chezhujie.www.persistence.TclauseMapper;
import com.xy.core.page.Pagination;
import com.xy.core.utils.UUIDUtils;



@Service("tclauseService")
public class TclauseService {
	@Autowired
	private TclauseMapper tclauseMapper;

	/**
	 * 查询某个条款内容（t_clause)
	 * @param param
	 * @return
	 */
	public Tclause getTclause(Map<String,Object> param) {
		return tclauseMapper.getTclause(param);
	}
	
	/**
	 * 查询某个条款内容（t_clause)
	 * @param param
	 * @return
	 */
	public Tclause getTclauseByType(Map<String,Object> param) {
		return tclauseMapper.getTclauseByType(param);
	}	
   
	/**
	 * 查询条款内容（t_clause)列表
	 * @return
	 */
	public Map<String,Object> getTclauseList(Map<String,Object> param) {
		Map<String,Object> returnMap = new HashMap<String,Object>();
		returnMap.put("totalCounts", tclauseMapper.getTotalRows(param));
		returnMap.put("list", tclauseMapper.getTclauseList(param));
		return returnMap;
	}
   
	/**
	 * 查询条款内容（t_clause)列表
	 * @return
	 */
	public  Pagination getTclauseList(Map<String,Object> param,int pageSize,Integer pageNo,String order,String sort) {
		Pagination p = new Pagination();
		p.setPageNo(pageNo);
		p.setPageSize(pageSize);
		p.setOrder(order);
		p.setSort(sort);
		param.putAll(p.toMap());
		int count=tclauseMapper.getTotalRows(param);
		List<Tclause> list=	tclauseMapper.getTclauseList(param);
	
		p.setList(list);
		p.setTotalCount(count);
		return p;
		
	}
      
	/**
	 * 新增条款内容（t_clause)
	 * @param tclause
	 * @param param
	 */
	@Transactional
	public void insertTclause(Tclause tclause) {
		tclause.setClauseId(UUIDUtils.getUUID());
		tclauseMapper.insertTclause(tclause);
	}
   
	/**
	 * 编辑条款内容（t_clause)
	 * @param tclause
	 * @param param
	 */
	@Transactional
	public void updateTclause(Tclause tclause) {
		tclauseMapper.updateTclause(tclause);
	}
   
	/**
	 * 删除条款内容（t_clause)
	 * @param param
	 */    
	@Transactional
	public void deleteTclause(List<String> clauseIdList) {
		for(String clauseId: clauseIdList){
	  		Map<String,Object> param = new HashMap<String,Object>();
	  		param.put("clauseId", clauseId);
	 	   tclauseMapper.deleteTclause(param);	  		
		}
	}
	/**
	 * 根据类型查询条款
	 * @param param
	 */    
	@Transactional
	public Tclause getByType(Map<String,Object> param) {
		return tclauseMapper.getByType(param);	  		
	}


}